home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3861 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: damon.irf.uni.dortmund.de!broth
  2. From: rothert@damon.irf.uni-dortmund.de (Bernd Rothert)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: BORLAND C++ 4.5 wont add .1 and .9
  5. Date: Fri, 26 Jan 96 11:47:09 GMT
  6. Organization: Institute of Robotics Research
  7. Message-ID: <4eaf69$4oj@damon.irf.uni-dortmund.de>
  8. References: <corekinDLG8t4.3C5@netcom.com> <4e5njv$e9v@damon.irf.uni-dortmund.de> <4e8e80$jdc@linet02.li.net>
  9. NNTP-Posting-Host: broth.irf
  10. X-Newsreader: News Xpress Version 1.0 Beta #4
  11.  
  12. In article <4e8e80$jdc@linet02.li.net>, bsilvern@li.net (Bob Silvern) wrote:
  13. >>#include <stdio.h>
  14. >>int one(void) { return 1; }
  15. >>int main(void)
  16. >>{
  17. >>    int zero = 0;
  18. >>    int two = (zero == 0) ? one()+1 : zero+1;
  19. >>    printf("one() plus 1 is %d\n", two);
  20. >>    return 0;
  21. >>}
  22. >>    one() plus 1 is 1
  23. >above code on Borland 4.02 and it worked correctly.  I'm curious what the
  24. >problem really is.  Is it a problem with the ? operator within the definition
  25. >of the variable "two"?  Is it calling the function one() from within the
  26. >definition of "two".  Is it a printf bug? None of these seems likely.  
  27.  
  28. It's the ? operator as you can see in the assembler source (bcc -B onetwo.c):
  29. ---- cut
  30. _main   proc    near
  31.         enter   2,0
  32.         push    si
  33.         xor     si,si
  34.         or      si,si
  35.         jne     short @2@86
  36.         call    near ptr @one$qv    ;<-call one(), result in AX but
  37.         jmp     short @2@114        ;<-no inc/add
  38. @2@86:
  39.         lea     ax,word ptr [si+1]    ;<- : zero+1
  40. @2@114:
  41.         mov     word ptr [bp-2],ax
  42.         push    word ptr [bp-2]
  43.         push    offset DGROUP:s@
  44.         call    near ptr _printf
  45.         add     sp,4
  46.         xor     ax,ax
  47. ---- cut
  48.  
  49. Bernd
  50.